#include <QDateTime> // for QDateTime
#include <QDebug> // for QDebug
#include <QList> // for QList, QList<>::const_iterator, QList<>::const_reverse_iterator, QList<>::count, QList<>::reverse_iterator
-#include <QScopedPointer> // for QScopedPointer
-#include <QScopedPointerPodDeleter> // for QScopedPointerPodDeleter
#include <QString> // for QString
#include <QStringView> // for QStringView
#include <QTextCodec> // for QTextCodec
return s1.left(n).compare(s2.left(n), Qt::CaseInsensitive);
}
-[[gnu::format(printf, 2, 3)]] int xasprintf(char** strp, const char* fmt, ...);
-[[gnu::format(printf, 2, 3)]] int xasprintf(QString* strp, const char* fmt, ...);
-[[gnu::format(printf, 2, 3)]] int xasprintf(QScopedPointer<char, QScopedPointerPodDeleter>& strp, const char* fmt, ...);
-[[gnu::format(printf, 2, 0)]] int xvasprintf(char** strp, const char* fmt, va_list ap);
char* strupper(char* src);
char* strlower(char* src);
QDateTime make_datetime(QDate date, QTime time, bool is_localtime, bool force_utc, int utc_offset);
static int datum_index;
static const char* datum_str;
static int current_line;
-static char* date_time_format = nullptr;
+static QString date_time_format;
static int precision = 3;
static time_t utc_offs = 0;
static gtxt_flags_t gtxt_flags;
const char* t = get_option_val(opt_time_format, kDefaultTimeFormat);
QString t1 = convert_human_time_format(t);
- xasprintf(&date_time_format, "%s %s", CSTR(d1), CSTR(t1));
+ date_time_format = QStringLiteral("%1 %2").arg(d1, t1);
}
static void
} else {
tm = *localtime(&time);
}
- strftime(tbuf, sizeof(tbuf), date_time_format, &tm);
+ strftime(tbuf, sizeof(tbuf), CSTR(date_time_format), &tm);
*fout << QString::asprintf("%s ", tbuf);
}
*fout << "\t";
fout->close();
delete fout;
fout = nullptr;
- xfree(date_time_format);
+ date_time_format.clear();
+ date_time_format.squeeze();
}
static void
static QDateTime
parse_date_and_time(const QString& str)
{
- QString timespec = strftime_to_timespec(date_time_format);
+ QString timespec = strftime_to_timespec(CSTR(date_time_format));
return QDateTime::fromString(QString(str).trimmed(), timespec);
}
fin->close();
delete fin;
fin = nullptr;
- xfree(date_time_format);
+ date_time_format.clear();
+ date_time_format.squeeze();
}
static void
if (hum.icon == 255) { /* no success, no try to find the item in a more comlex name */
hum.icon = 0; /* i.e. "Diamond" as part of "Diamond, Green" or "Green Diamond" */
for (int i = 0; i < num_icons; i++) {
- char* match;
- xasprintf(&match, "*%s*", humminbird_icons[i]);
- int j = wpt->icon_descr.compare(match, Qt::CaseInsensitive);
- xfree(match);
- if (j != 0) {
+ if (wpt->icon_descr.contains(humminbird_icons[i], Qt::CaseInsensitive)) {
hum.icon = i;
break;
}
be_write32(&hum.north, qRound(north));
QString name = (global_opts.synthesize_shortnames)
- ? mkshort_from_wpt(wptname_sh, wpt)
- : mkshort(wptname_sh, wpt->shortname);
+ ? mkshort_from_wpt(wptname_sh, wpt)
+ : mkshort(wptname_sh, wpt->shortname);
memset(&hum.name, 0, sizeof(hum.name));
memcpy(&hum.name, CSTR(name), name.length());
void
HumminbirdFormat::humminbird_write_waypoint_wrapper(const Waypoint* wpt)
{
- char* key;
Waypoint* tmpwpt;
- xasprintf(&key, "%s\01%.9f\01%.9f", CSTRc(wpt->shortname), wpt->latitude, wpt->longitude);
+ QString key = QStringLiteral("%1\01%2\01%3").arg(wpt->shortname)
+ .arg(wpt->latitude, 0, 'f', 9).arg(wpt->longitude, 0, 'f', 9);
if (!(tmpwpt = map[key])) {
tmpwpt = const_cast<Waypoint*>(wpt);
map[key] = const_cast<Waypoint*>(wpt);
tmpwpt = const_cast<Waypoint*>(wpt);
tmpwpt->extra_data = p;
}
-
- xfree(key);
}
void
*sectors_total = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_total);
// unsigned char log_bool, fifo_mode;
- char* mystatus;
unsigned int tmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_time);
unsigned int tmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_time);
unsigned int dmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_dist);
unsigned int vmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_speed);
// log_bool = *(MSG_LOG_STATUS_OUTPUT.datalog_enable);
// fifo_mode = *(MSG_LOG_STATUS_OUTPUT.log_fifo_mode);
- xasprintf(&mystatus, "#logging: tmin=%u, tmax=%u, dmin=%u, dmax=%u, vmin=%u, vmax=%u\n", tmin, tmax, dmin, dmax, vmin, vmax);
- db(1, mystatus);
- xfree(mystatus);
+ db(1, "#logging: tmin=%u, tmax=%u, dmin=%u, dmax=%u, vmin=%u, vmax=%u\n", tmin, tmax, dmin, dmax, vmin, vmax);
return res_OK;
}
#include <cerrno> // for errno
#include <climits> // for INT_MAX, INT_MIN
#include <cmath> // for fabs, floor
-#include <cstdarg> // for va_list, va_end, va_start, va_copy
#include <cstdio> // for size_t, vsnprintf, FILE, fopen, printf, sprintf, stderr, stdin, stdout
#include <cstdlib> // for abs, calloc, free, malloc, realloc
#include <cstring> // for strlen, strcat, strstr, memcpy, strcmp, strcpy, strdup, strchr, strerror
#include <QDateTime> // for QDateTime
#include <QFileInfo> // for QFileInfo
#include <QList> // for QList
-#include <QScopedPointer> // for QScopedPointer
#include <QString> // for QString
#include <QTextBoundaryFinder> // for QTextBoundaryFinder, QTextBoundaryFinder::Grapheme
#include <QTextCodec> // for QTextCodec
#endif
}
-/*
- * Allocate a string using a format list with optional arguments
- * Returns -1 on error.
- * If return value is anything else, *strp will be populated with an
- * allocated string containing the formatted buffer.
- *
- * Freeing that is the responsibility of the caller.
- */
-
-int
-xasprintf(char** strp, const char* fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- int res = xvasprintf(strp, fmt, args);
- va_end(args);
-
- return res;
-}
-
-int
-xasprintf(QString* strp, const char* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- char* cstrp;
- int res = xvasprintf(&cstrp, fmt, args);
- *strp = cstrp;
- xfree(cstrp);
- va_end(args);
-
- return res;
-}
-
-int
-xasprintf(QScopedPointer<char, QScopedPointerPodDeleter>& strp, const char* fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- char* cstrp;
- int res = xvasprintf(&cstrp, fmt, args);
- strp.reset(cstrp);
- va_end(args);
-
- return res;
-}
-
-int
-xvasprintf(char** strp, const char* fmt, va_list ap)
-{
- /* From http://perfec.to/vsnprintf/pasprintf.c */
- /* size of first buffer malloc; start small to exercise grow routines */
-# define FIRSTSIZE 1
- char* buf = nullptr;
- char* newbuf;
- size_t nextsize = 0;
- int outsize;
- va_list args;
-
- int bufsize = 0;
- for (;;) {
- if (bufsize == 0) {
- if ((buf = (char*) xmalloc(FIRSTSIZE)) == nullptr) {
- *strp = nullptr;
- return -1;
- }
- bufsize = FIRSTSIZE;
- } else if ((newbuf = (char*) xrealloc(buf, nextsize)) != nullptr) {
- buf = newbuf;
- bufsize = nextsize;
- } else {
- xfree(buf);
- *strp = nullptr;
- return -1;
- }
-
- va_copy(args, ap);
- outsize = vsnprintf(buf, bufsize, fmt, args);
- va_end(args);
-
- if (outsize == -1) {
- /* Clear indication that output was truncated, but no
- * clear indication of how big buffer needs to be, so
- * simply double existing buffer size for next time.
- */
- nextsize = bufsize * 2;
-
- } else if (outsize == bufsize) {
- /* Output was truncated (since at least the \0 could
- * not fit), but no indication of how big the buffer
- * needs to be, so just double existing buffer size
- * for next time.
- */
- nextsize = bufsize * 2;
-
- } else if (outsize > bufsize) {
- /* Output was truncated, but we were told exactly how
- * big the buffer needs to be next time. Add two chars
- * to the returned size. One for the \0, and one to
- * prevent ambiguity in the next case below.
- */
- nextsize = outsize + 2;
-
- } else if (outsize == bufsize - 1) {
- /* This is ambiguous. May mean that the output string
- * exactly fits, but on some systems the output string
- * may have been truncated. We can't tell.
- * Just double the buffer size for next time.
- */
- nextsize = bufsize * 2;
-
- } else {
- /* Output was not truncated */
- break;
- }
- }
- /* Prevent us from allocating millions of unused bytes. */
- /* O.K.: I think this is not the final solution. */
- if (bufsize > outsize + 1) {
- const unsigned ptrsz = sizeof(buf);
- if (((bufsize + ptrsz + 1) / ptrsz) > ((outsize + ptrsz + 1) / ptrsz)) {
- buf = (char*) xrealloc(buf, outsize + 1);
- }
-
- }
- *strp = buf;
- return outsize;
-}
-
void
printposn(const double c, bool is_lat)
{